<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<meta http-equiv="Refresh" content="100;URL=http://www.baidu.com" />
	<script type="text/javascript" src="js/jquery-1.6.1.min.js"></script>
	<script type="text/javascript">
		function register(){
			var name = $("#i_name").val();
			var pass = $("#i_pass").val();
			if(name == null || name == "" || pass == null || pass == ""){
				alert("用户或密码不能为空");
			}else{
				var url = "checkname";
				$.get(url,{name:name},function(result){
					var sex = $("input[name='sex']:checked").val();
					//$.post(register,{name:encodeURIComponent(name),pass:pass,sex:sex});
					location.href="register?name="+encodeURIComponent(name)+"&pass="+pass+"&sex="+sex;	
				});
			}
		}
		
		function checkNameRepeat(){
			var name = $("#i_name").val();
			var url = "checkname";
			$.get(url,{name:name},function(result){
				if(result == "error"){
					$("#checkname").html("<font color='red'>用户已存在</font>");
					$("#iname").focus();
					return "false";
				}else{
					return "true";
				}
			})
		}
	</script>
  </head>
  
  <body>
   100秒钟跳转....
	<center>welcome to sy perfectfood center !!!</center>
  	<center>
  		<table>
  			<%if(request.getAttribute("result") != null){ %>
  				<tr>
  					<td colspan="2"><font color="red">${result }</font></td>
  				</tr>
  			<%} %>
  			<tr>
  				<td>姓名：</td>
  				<td><input type="text" name="name" id="i_name" onblur="checkNameRepeat()"/><span id="checkname"></span></td>
  			</tr>
  			<tr>
  				<td>密码：</td>
  				<td><input type="password" name="pass" id="i_pass"/></td>
  			</tr>
  			<tr>
  				<td>性别：</td>
  				<td>
  				<input type="radio" name="sex" value="1" checked/>男
  				<input type="radio" name="sex" value="0"/>女
  				</td>
  			</tr>
  			<tr>
  				<td><input type="button" value="注册" onclick="register();"/></td>
  				<td><input type="button" value="返回" onclick="history.go(-1);"/></td>
  			</tr>
  		</table>
  	</center>
  </body>
</html>
